package com.vatata.wae.jsobject;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;

import com.vatata.wae.WaeAbstractJsObject;

public class LanguageUtils extends WaeAbstractJsObject {
    // TODO, more object
    private android.content.Intent startIntent = null;
    /**
     * 设置识别语言
     *
     * @param context
     * @param msgText
     */
    public static final String ASR_LANG = "asr.lang";
    public static final String ASR_LANG_DEFAULT = "asr.lang.default";
    public static final String ASR_LANG_CHINESE = "asr.lang.zh";//chinese language
    public static final String ASR_LANG_ENGLISH = "asr.lang.en";//english
    public static final String ASR_LANG_MALAY = "asr.lang.bm";//马来语
    public static final String ASR_LANG_VIETNAMESE = "asr.lang.ta";//越南语
    public static final String ASR_LANG_CHINESE_YUEYU = "asr.lang.zh.yueyu";
    public static final String ASR_LANG_CHINESE_SICHUAN = "asr.lang.zh.sichuan";
    public static final String ASR_LANG_CHINESE_SHANXI = "asr.lang.zh.shanxi";//陕西话

    @Override
    protected void init() {

    }

    public void setLanguage(String language){
        Log.d("SetLanguage", language );
        if(startIntent == null){
            startIntent = new android.content.Intent();
        }

        startIntent.setClassName("com.peasun.aispeechgl","com.peasun.aispeech.AIMonitorService");
        Bundle data = new Bundle();
        switch (language){
            case "cn":
            case "tw":
                Log.d("ASR_LANG_CHINESE", language );
                data.putString(ASR_LANG, ASR_LANG_CHINESE);
                break;
            case "ta":
                data.putString(ASR_LANG, ASR_LANG_VIETNAMESE);
                break;
            case "bm":
                data.putString(ASR_LANG, ASR_LANG_MALAY);
                break;
            default:
                Log.d("ASR_LANG_ENGLISH", language );
                data.putString(ASR_LANG, ASR_LANG_ENGLISH);
                break;
        }

        startIntent.putExtras(data);
        //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //context.startService(intent);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            view.activity.startForegroundService(startIntent);
        } else {
            view.activity.startService(startIntent);
        }
    }
}
